//
//  ArrayDataSource.m
//  27-ArrayDataSource
//
//  Created by 王道林 on 16/8/19.
//  Copyright © 2016年 王道林. All rights reserved.
//

#import "ArrayDataSource.h"

@interface ArrayDataSource ()

// 声明全局的属性
@property (nonatomic, copy) NSString *reuse;
@property (nonatomic, strong) NSArray *dataSource;
@property (nonatomic, copy) configCell configCell;
@end

@implementation ArrayDataSource

- (instancetype)initWithTableViewCellReuse:(NSString *)reuse arrayDataSource:(NSArray *)array configCell:(configCell)configCell
{
    self = [super init];
    if (self) {
        _reuse = reuse;
        _dataSource = array;
        _configCell = configCell;
    }
    return self;
}

+ (ArrayDataSource *)ArrayDataSourceWithTableViewCellReuse:(NSString *)reuse arrayDataSource:(NSArray *)array configCell:(configCell)configCell
{
    return [[self alloc] initWithTableViewCellReuse:reuse arrayDataSource:array configCell:configCell];
}




- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _dataSource.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:_reuse forIndexPath:indexPath];
    NSString *model = _dataSource[indexPath.row];
    self.configCell(cell, model);
    return cell;
}



@end
